#pragma once
#include <stdio.h>
#include <ctime>
//#include "SDL.h"
//#include "SDL_image.h"
#include "sdl\include\SDL.h"
#include "sdl\include\SDL_image.h"
#include "dv_sdlgrafix.h"

// where to draw on the screen
const int X_OFFSET = 5;
const int Y_OFFSET = 50;

struct DiceNum{
	int value;
	int index;
};

class Dice
{
public:
	/*--- Constructor ---*/
	Dice():xPos(0), yPos(0), frozenDice(false){
		dNum.index = dNum.value = 0;
		time_t seed = clock();
		srand(time(&seed));
	}

	void release()
	{
		SDL_FreeSurface(dice1);
		SDL_FreeSurface(dice2);
	}
	void initialize()
	{
		dice1 = load_image("dice.png");
		dice2 = load_image("dice2.png");
	}
	void diceRoll() { dNum.value = rand()%6 + 1; }

	void draw(SDL_Surface *a_buffer, int a_index, int a_x)
	{
		// 50x50 px dice image
		SDL_Rect rect={0,0,dice1->h,dice1->h};
		drawTile(dice1, &rect, a_index, a_buffer, a_x+X_OFFSET, Y_OFFSET);
	}

	// draws frozen tile
	void drawF(SDL_Surface *a_buffer, int a_index, int a_x)
	{
		SDL_Rect rect={0,0,dice2->h,dice2->h};
		drawTile(dice2, &rect, a_index, a_buffer, a_x+X_OFFSET, Y_OFFSET);
	}
	// mutataor & Accessor
	void setPosition(int a_x, int a_y)
	{
		xPos = a_x;
		yPos = a_y;
	}
	void setFreeze(bool a_value) { frozenDice = a_value; }
	void setDiceIndex(int a_index) { dNum.index = a_index; }
	bool isFrozen() { return frozenDice; }
	int getDiceIndex() { return dNum.index; }
	int getDiceValue() { return dNum.value; }

private:
	// The surfaces
	SDL_Surface *dice1;
	SDL_Surface *dice2;
	// the value and index of the dice
	DiceNum dNum;
	// current location on the board
	int xPos, yPos;
	// has the player frozen this dice
	bool frozenDice;
};